package org.freeone.learning.springbootsecurity.service.service.impl;

import org.freeone.learning.springbootsecurity.entity.TbUser;
import org.freeone.learning.springbootsecurity.service.UserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@Service
public class UserServiceImpl implements UserService {

    private Map<String, String> usernamePasswordMap = new HashMap<String, String>() {{
        put("user", "123456");
        put("admin", "123456");
    }};

    /**
     * 模拟数据库查询
     *
     * @param username
     * @return
     */
    @Override
    public TbUser getByUsername(String username) {
        String password = usernamePasswordMap.get(username);
        if (password != null) {
            TbUser tbUser = new TbUser();
            tbUser.setUsername(username);
            tbUser.setPassword(password);
            return tbUser;
        } else {
            return null;
        }

    }

    @Override
    public Set<String> ListPermissions(String username) {
        Set<String> permissions = new HashSet<>();
        permissions.add("sys:user:select");
        permissions.add("sys:user:insert");
        permissions.add("sys:user:update");
        permissions.add("sys:user:delete");
        return permissions;
    }
}
